package com.wry.spring.extension;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * <h1> springmvc-扩展点 </h1>
 *
 * @author wry
 * @since 2025.04.06
 */
public class AuthInterceptor extends HandlerInterceptorAdapter {


    // 目标方法执行请求前
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String auth = request.getHeader("auth");
        String auths = "DOASDJASJFASKNKAS12A1D2AS1D";
//        if (auth.equals(auths)) {
//            System.out.println("权限校验成功");
//            return true;
//        }
        return true;
//        throw new Exception("权限校验失败");
    }

    // 目标方法执行请求后
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        super.postHandle(request, response, handler, modelAndView);
    }

    // 目标方法完成请求时
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        super.afterCompletion(request, response, handler, ex);
    }
}
